﻿using System;
using System.Collections.Generic;
using System.Web;
//using NewThinkings.BusinessLayer.BusinessObjects.Core;
using System.Text;
//using PMSA.iMarkets.Presentation.WebApp.Mods.Global;
using NewThinkings.BusinessLayer.BusinessObject;

namespace Presentation.WebApp.Mods.Front
{
    public class CModuleUI
    {
        #region Private member
        public CModule Module;
        #endregion

        #region Public property

        #endregion

        #region Constructor
        public CModuleUI(CModule module)
        {
            Module = module;
        }
        public CModuleUI() { }
        #endregion

        #region Dispose

        #endregion

        #region Infomation
        public static string GetModuleImage()
        {
            System.Threading.Thread.Sleep(10);
            string[] css = { "ss_tag_orange", "ss_tag_pink", "ss_tag_red", "ss_tag_yellow", "ss_tag_purple", "ss_tag_blue", "ss_tag_green", "ss_award_star_gold_1", "ss_award_star_gold_2", "ss_award_star_gold_3", "ss_layout", "ss_lightning" };
            string sprite = string.Format("<span class='ss_sprite {0}'> &nbsp;</span>",            
                css[new Random().Next(css.Length)]);
            return sprite;
        }

        public string GetHtmlWithInterfaceFuntion()
        {
            return GetHtmlWithInterfaceFuntion("");
        }
        public string GetHtmlWithInterfaceFuntion(string aClass)
        {
            //<ul>
            //            <li>
            //            <a href="#america-newyork">New York</a>
            //                <div>
            //                    <a href="">Nothing1</a>
            //                    <a href="">Nothing2</a>
            //                </div>
            //            </li>
            //        </ul>

            StringBuilder ret = new StringBuilder();
            ret.Append("<li>");
            ret.Append(string.Format("<a href='javascript:void(0);' link='{0}' id='Mod_{1}' tabid='m{1}' isLoad='0' class='{3}' RetainPage='{5}'>{4} {2}</a>",
                            Module.LinkURL,
                            Module.ID,
                            Module.Name,
                            aClass,
                            GetModuleImage(),Module.RetainPage));

            //Get Interface Function of Module ----------------------------------------
            //CSession session = new CSession();
            //IList<CInterfaceFunction> listFunc = new CCoreFacade().GetInterfaceFunctionByModuleID(
            //            session.User.ID,
            //            session.SessionID.ToString(),
            //            Module.ID,
            //            session.LanguageID);
            //ret.Append(CInterfaceFunctionUI.GetHtml(listFunc));
            //--------------------------------------------------------------------------

            ret.Append("</li>");
            return ret.ToString();
        }

        #endregion

        #region Infomation - Static
        public static string GetHtml(IList<CModule> listMudule)
        {
            StringBuilder ret = new StringBuilder();
            ret.Append("<ul class='MenuMod'>");
            foreach (CModule mod in listMudule)
            {
                CModuleUI moduleUI = new CModuleUI(mod);
                string modClass = "";
                if (mod == listMudule[0])
                    modClass = "first";
                ret.Append(moduleUI.GetHtmlWithInterfaceFuntion(modClass));
            }
            ret.Append("</ul>");
            return ret.ToString();
        }
        #endregion
    }
}